package ionio.cscw.game;

import org.apache.tools.ant.taskdefs.Length;

public class GibberishCheck {

	private char vowels[] = {'A','E','I','O','U'};

	public boolean checkWord(String userWord){
		if(userWord.length()<=2){
			return false;
		}
		else { 
			int []gibberish_container = new int [userWord.length()];
			int j = 0;
			int vowel_counter = 0;
			int consonant_counter = 0;
			boolean isvowel=isVowel(userWord.charAt(0));
			for(int i=0 ; i<userWord.length() ; i++){				
				if(isVowel(userWord.charAt(i))) {
					vowel_counter++;
					if(!isvowel) {
						gibberish_container[j]=consonant_counter;						
						consonant_counter=0;
						j++;
					}
					isvowel=true;
				} else {
					consonant_counter++;
					if(isvowel) {
						gibberish_container[j]=vowel_counter;						
						vowel_counter=0;
						j++;
					}
					isvowel=false;
				}
			}
			if(vowel_counter!=0) {
				gibberish_container[j]=vowel_counter;						
			} else if(consonant_counter!=0) {
				gibberish_container[j]=consonant_counter;
			}
			int max = gibberish_container[0];
			for(int i=1;i<=j;i++){
				if(gibberish_container[i] > max){
					max = gibberish_container[i];
				}
			}
			if (max >= 4){
				return false;
			}
			int counter = 0;
			for(int i=0;i<=j;i++){
				if(gibberish_container[i] >= 3){
					counter ++;
				}
			}
			if (counter >= 2){
				return false;
			}
			
			return true;
		}
	}
	
	private boolean isVowel(char c) {
		for(char vowel :vowels){
			if(vowel == c){
				return true;
			}
		}
		return false;
	}

}
